//
//  YDHomeTopView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/8.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDHomeTopView.h"
#import "DRJCycleScrollView.h"
#import "YDHomeMarketView.h"
#import "YDHomeAdvertisementView.h"

@interface YDHomeTopView()<DRJCycleScrollViewDelegate , SYHomeMarketViewDelegate , SYHomeAdvertisementViewDelegate>
//轮播图
@property (nonatomic , weak) DRJCycleScrollView *cycleView;
//大盘走势view
@property (nonatomic , weak) YDHomeMarketView *marketView;
//公告轮播视图
@property (nonatomic , weak) YDHomeAdvertisementView *advertisementView;
@end

@implementation YDHomeTopView

-(void)setCarsoulImageUrlArray:(NSArray *)carsoulImageUrlArray
{
    _carsoulImageUrlArray = carsoulImageUrlArray;
    //刷新轮播图
    
    self.cycleView.imageURLStringsGroup = carsoulImageUrlArray;
}

-(void)setNoticeModelArray:(NSArray *)noticeModelArray
{
    _noticeModelArray =noticeModelArray;
    //刷新notice
    self.advertisementView.modelArray = [noticeModelArray mutableCopy];
}
-(void)setQuotationModelArray:(NSArray *)quotationModelArray
{
    _quotationModelArray = quotationModelArray;
    //刷新行情
    self.marketView.marketModelArray = quotationModelArray;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = NumberColor(247, 247, 247);
        
        [self cycleView];

        [self marketView];
    
        [self advertisementView];
    
    }
    return self;
}
+(instancetype)homeTopViewWithCarsoulImageUrlArray:(NSArray *)carsoulImageUrlArray NoticeModelArray:(NSArray *)noticeModelArray QuotationModelArray:(NSArray *)quotationModelArray
{
    YDHomeTopView *topView = [[self alloc] init];
    
    topView.carsoulImageUrlArray = carsoulImageUrlArray;
    topView.noticeModelArray = noticeModelArray;
    topView.quotationModelArray = quotationModelArray;
    
    return topView;
}
/*********轮播视图***********/
-(DRJCycleScrollView *)cycleView
{
    if (_cycleView == nil) {
        CGFloat cycleViewH;
        if (isPhoneX) {
            cycleViewH = rateX812(210);
        }else{
            cycleViewH = rate750(210);
        }
        DRJCycleScrollView *cycleView = [DRJCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, LKScreenW, cycleViewH) imageURLStringsGroup:self.carsoulImageUrlArray];
        [self addSubview:cycleView];
        cycleView.backgroundColor = [UIColor whiteColor];
        cycleView.titlesGroup=[NSArray array];
        cycleView.placeholderImage =[UIImage imageNamed:@"banner-bg"];
        cycleView.delegate = self;
        cycleView.pageControlStyle = DRJCycleScrollViewPageContolStyleAnimated;
        cycleView.pageControlAliment = DRJCycleScrollViewPageContolAlimentCenter;
        cycleView.dotColor = [UIColor whiteColor];
        cycleView.titleLabelTextFont=[UIFont systemFontOfSize:font26ScreenWRate * LKScreenW];
        cycleView.titleLabelHeight = 30;
        cycleView.width = LKScreenW;
        cycleView.height = cycleViewH;
        _cycleView = cycleView;
    }
    return _cycleView;
}
/*********DRJCycleScrollViewDelegate********/
-(void)cycleScrollView:(DRJCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    if ([_delegate respondsToSelector:@selector(homeTopView:didSelectedViewType:viewIndex:)]) {
        [_delegate homeTopView:self didSelectedViewType:SYHomeTopViewStyleCarsoul viewIndex:index];
    }
}

/*********大盘视图***********/
-(YDHomeMarketView *)marketView
{
    if (_marketView == nil) {
        CGFloat marketH;
        if (isPhoneX) {
            marketH = rateX812(80);
        }else{
            marketH = rate750(80);
        }
        YDHomeMarketView *marketView = [YDHomeMarketView homeMarketViewMarketModelArray:self.quotationModelArray];
        [self addSubview:marketView];
        marketView.delegate = self;
        marketView.frame = CGRectMake(0, CGRectGetMaxY(_cycleView.frame), LKScreenW, marketH);
        _marketView = marketView;
    }
    return _marketView;
}
/**********SYHomeMarketViewDelegate*************/
-(void)homeMarketView:(YDHomeMarketView *)homeMarketView didSelectItemAtIndex:(NSInteger)index
{
    if ([_delegate respondsToSelector:@selector(homeTopView:didSelectedViewType:viewIndex:)]) {
        [_delegate homeTopView:self didSelectedViewType:SYHomeTopViewStyleMarket viewIndex:index];
    }
}

/***********公告轮播视图*************/
-(YDHomeAdvertisementView *)advertisementView
{
    if (_advertisementView == nil) {
        CGFloat margin;
        CGFloat viewH;
        if (isPhoneX) {
            margin = rateX812(5);
            viewH = rateX812(38);
        }else{
            margin = rate750(5);
            viewH = rate750(38);
        }
        YDHomeAdvertisementView *advertisementView = [YDHomeAdvertisementView homeAdvertisementViewWithFrame:CGRectMake(0, CGRectGetMaxY(_marketView.frame) + margin, LKScreenW, viewH) ModelArray:[self.noticeModelArray copy]];
        [self addSubview:advertisementView];
        advertisementView.delegate = self;
        _advertisementView = advertisementView;
    }
    return _advertisementView;
}

/************SYHomeAdvertisementViewDelegate*************/
-(void)homeAdvertisementView:(YDHomeAdvertisementView *)advertisementView didClickCellIndex:(NSInteger)index
{
    if ([self.delegate respondsToSelector:@selector(homeTopView:didSelectedViewType:viewIndex:)]) {
        [self.delegate homeTopView:self didSelectedViewType:SYHomeTopViewStyleRotation viewIndex:index];
    }
}
@end
